#ifndef	__NCS8801_h__
#define	__NCS8801_h__

#include "stdint.h"
#include <stdbool.h>
#include <integer.h>
#include <IOConfig.h>

#define DEVICE_ADDRESS_VDDIO	0x58			
#define DEVICE_ADDRESS_VDD	    0x5E	
#define DEVICE_ADDRESS_DVDD  0x5C
//#define DEVICE_ADDRESS_M5	0x5C			

#define COMMAND_NOP_INDEX			0x00
#define COMMAND_WRITE_RDAC_INDEX	0x01
#define COMMAND_READ_RDAC_INDEX		0x02
#define COMMAND_STORE_RDAC_SETTNG_INDEX		0x03
#define COMMAND_REFRESH_RDAC_INDEX		0x04
#define COMMAND_READ_OTP_CONTENT_INDEX		0x05
#define COMMAND_READ_OTP_INDEX		0x06
#define COMMAND_WRITE_CONTROL_INDEX		0x07
#define COMMAND_READ_CONTROL_INDEX		0x08
#define COMMAND_SHUTDOWN_INDEX		0x09


#define NCS8801PIN_SCL  GPIO_PIN_3
#define NCS8801PIN_SDA  GPIO_PIN_15						//­×
#define GPIO_NCS8801_SDA                                   GPIOB
#define GPIO_NCS8801_SCL                                   GPIOD

#define eDP_IIC_PIN_SCL  GPIO_PIN_12
#define eDP_IIC_PIN_SDA  GPIO_PIN_13						//­×
#define GPIO_eDP_IIC__SDA                                   GPIOD
#define GPIO_eDP_IIC__SCL                                   GPIOD

#define eDP_IIC_TPSCL_L HAL_GPIO_WritePin(GPIO_eDP_IIC__SCL, eDP_IIC_PIN_SCL,GPIO_PIN_RESET)  //SCL
#define eDP_IIC_TPSCL_H HAL_GPIO_WritePin(GPIO_eDP_IIC__SCL, eDP_IIC_PIN_SCL,GPIO_PIN_SET)
#define eDP_IIC_TPSDA_L HAL_GPIO_WritePin(GPIO_eDP_IIC__SDA, eDP_IIC_PIN_SDA,GPIO_PIN_RESET)  //SDA
#define eDP_IIC_TPSDA_H HAL_GPIO_WritePin(GPIO_eDP_IIC__SDA, eDP_IIC_PIN_SDA,GPIO_PIN_SET)

#define FPCIIC_SCL  GPIO_PIN_2
#define FPCIIC_SDA  GPIO_PIN_1						//­×
#define GPIO_FPCIIC_SDA                                   GPIOE
#define GPIO_FPCIIC_SCL                                   GPIOE

//------------------------------------------------------------
#define NCS8801_TPSCL_L HAL_GPIO_WritePin(GPIO_NCS8801_SCL, NCS8801PIN_SCL,GPIO_PIN_RESET)  //SCL
#define NCS8801_TPSCL_H HAL_GPIO_WritePin(GPIO_NCS8801_SCL, NCS8801PIN_SCL,GPIO_PIN_SET)
#define NCS8801_TPSDA_L HAL_GPIO_WritePin(GPIO_NCS8801_SDA, NCS8801PIN_SDA,GPIO_PIN_RESET)  //SDA
#define NCS8801_TPSDA_H HAL_GPIO_WritePin(GPIO_NCS8801_SDA, NCS8801PIN_SDA,GPIO_PIN_SET)

void NCS8801_Init(u16 status);
void NCS8801_GPIO_Config(void);
void NCS8801_I2CSDASetInput(void);
void NCS8801_I2CSDASetOutput(void);
void NCS8801_I2CStart(void);
void NCS8801_I2CStop(void);
bool NCS8801_I2CSendByte(BYTE ucData);
BYTE NCS8801_I2CReciveByte(bool bAck);
bool NCS8801_I2CSend(BYTE ucDeviceAddr, BYTE ucIndex, u16 RDACValue);
bool NCS8801_I2CReceive(BYTE ucDeviceAddr, BYTE ucIndex, BYTE* pucData, unsigned int unDataLength);
bool NCS8801_I2CReceive_A(BYTE ucDeviceAddr, BYTE ucIndex, BYTE* NCS8801_pucData); //(器件地址，buffer类型，被读出数据保存位置)

unsigned int NCS8801_BUS_VOLTAGE(void);
void VDD_NCS8801_Init(u16 uvol);  
void VDDIO_NCS8801_Init(u16 uvol);
void DVDD_NCS8801_Init(u16 uvol);
void DelayMs(u16 x);
void IIC_BIST_Puer_color(u8 R_color,u8 G_color,u8 B_color);
void IIC_BIST_LOGIC_NT71181_USE(u8 byte);

void NCS8801_I2CStart_device(u8 channel);
void NCS8801_I2CStop_device(u8 channel);
bool NCS8801_I2CSend_Array_IIC_xxBIT_1v8(u8 SigMode ,u8 offerset,u8* para);
bool NCS8801_I2CReceive_TCON_1v8(BYTE ucDeviceAddr, BYTE ucIndex,u8* buffer, BYTE* NCS8801_pucData);


bool IIC_xxBIT_1v8_Array(u8 IIC_Channel,u8 ucDeviceAddr, u8 unDataLength,u8 *buf);

int SSD2828_W_RAM_buffer_8bits_part_IIC(float pclk,u8 SigMode ,u8* buffer ,u16 length,u8  multiple ,u8 Flag,u8 DisMode);////IIC送图，项目临时测试用
//-----------------------------------------------------------------------
#endif
